'use strict';

const Controller = require('egg').Controller;


// 定义校验规则
const createRule = {
    id: {
        required: false,
        type: 'number'
    },
    name: 'string'
};

// 菜单的id，以字符串的形式存
// 1,2,3,4
// r,c

class HomeController extends Controller {
    async index() {
        this.ctx.response.body = {
            msg: '我是index控制器'
        }
    }
    async create() {
        try {
            this.ctx.validate(createRule, this.ctx.request.body)
            this.ctx.response.body = {
                msg: '我是create控制器'
            }
            
        } catch(e) {
            this.ctx.response.body = {
                code: 0,
                msg: e.message
            }
        }
    }
    async login() {
        console.log(123)
        const { name, password } = this.ctx.request.body
        // result
        const res = await this.service.user.login({
            name, password
        })

        console.log(res)
        this.ctx.response.body = res
    }
}

module.exports = HomeController;
